home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1089 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: bessel.nando.net!validatr
  2. From: validatr@nando.net (validatr)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Infrequent use of do while, C Idioms
  5. Date: 11 Jan 1996 12:24:26 GMT
  6. Organization: NandO.net
  7. Distribution: world
  8. Message-ID: <4d2vhq$rir@castle.nando.net>
  9. References: <49slsq$10l@panix2.panix.com> <4a5pk6$pvd@ixnews6.ix.netcom.com> <1995Dec7.154222.9354@lamont.ldgo.columbia.edu> <1996Jan2.150509@hsun13.hou281.chevron.com>
  10. NNTP-Posting-Host: bessel.nando.net
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. Actually the do while command is quite useful if you want to execute some 
  14. code at least once and then conditionally.  This saves you from writing 
  15. something like:
  16.  
  17. perform x
  18. while(condition) {perform x}
  19.  
  20. which is something we all have seen.  It is less code and still 
  21. completely understandable to do the following:
  22.  
  23. do {perform x} while (condition)
  24.  
  25. I like the command and have used it frequently.
  26.  
  27. C.W.Racer (gacwra@hsun13.hou281.chevron.com) wrote:
  28. : In article <1995Dec7.154222.9354@lamont.ldgo.columbia.edu>, mike@armchair.mb.ca (Mike Forster) writes:
  29. : |> cjds@ix.netcom.com (Bill Horger) wrote:
  30. : |> 
  31. : |> [snipped]
  32. : |> 
  33. : |> >
  34. : |> >| So, anyhow, I was thinking and I realized that I have never ever seen
  35. : |> >| a
  36. : |> >| do {
  37. : |> >| } while (condition)
  38. : |> >
  39. : ---------------------------------stuff deleted -----------------------
  40.  
  41. : The issue here is do you want the loop 'top-tested' or 'bottom-tested'?
  42. : Most c programmers prefer (seems to me) the top-tested loop.  Once in a
  43. : while I'll find the other one seems to fit better.  
  44.  
  45. : PL/1 DO loops allow both (using the 'while' and 'until' for top and
  46. : bottom tested).  I actually used that once but only because it intrigued
  47. : me.
  48. : -- 
  49. : | Chick Racer                     Chevron Petroleum Technology Co. |
  50. : | (713) 596-2430                  P.O. Box 42832                   |
  51. : | gacwra@chevron.com              Houston, Tx 77242-2832           |
  52. : | 4119 Hayes Rd.                                                   |
  53.  
  54. --
  55. **************************************************************************
  56. "In God we trust, all others require documented evidence" Validation Creed
  57. "If I had known I would live this long, I would have taken better care of
  58. myself"  validatr@nando.net is Bob Whitener, the Validator 0==|======> 
  59.